import { validateNotJSkeyWord } from '../../../../../../../../common/utils/validate'
import { getApiList, getDictionaryTypeList } from '../../../../service'

let variableValidator = (rule, value, callback) => {
  const re = /^[a-zA-Z\u4e00-\u9fa5][a-zA-Z\d_\u4e00-\u9fa5]*$/
  if (!re.test(value)) {
    callback(new Error('字段名必须以字母开头，且只能包含字母、数字、下滑线）'))
    return
  }
  if (!validateNotJSkeyWord(value)) {
    callback(new Error('不能使用js保留字段'))
    return
  }
  callback()
}
export default {
  labelWidth: '94px',
  gap: '12px',
  groupTheme: 'collapse',
  groups: [
    {
      title: '组件配置',
      columnsCount: 2,
      items: [
        {
          type: 'input',
          label: '标识',
          prop: 'componentId',
          readonly: true
        },
        {
          label: '绑定方法',
          prop: 'bindMethod',
          type: 'radio',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [
              {
                label: '字典',
                value: 1
              },
              {
                label: '输入',
                value: 2
              }
            ]
          }
        },
        {
          type: 'select',
          label: '关联字典',
          prop: 'propertyType',
          config: {
            optionsValueKey: 'id',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getDictionaryTypeList()
            }
          },
          rules: [{ required: true, message: '请选择绑定值类型', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'bindSelect',
          label: '绑定值',
          prop: 'propertyName',
          config: {
            bindProp: 'propertyType',
            optionsValueKey: 'tagValue',
            optionsLabelKey: 'dicTagName',
            returnObject: false,
          },
          rules: [{ required: true, message: '请选择绑定值', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '绑定值',
          prop: 'propertyName',
          rules: [{ required: true, message: '请输入绑定值', trigger: 'change' }],
          exist(value) {
            if (value.bindMethod === 2) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '名称',
          prop: 'name',
          rules: [{ required: true, message: '请输入控件名称', trigger: 'blur' }]
        },
        {
          type: 'bindLabel',
          label: '标签',
          prop: 'label',
          readonly: true,
          config: {
            bindProp: 'propertyName',
            subordinateProp: 'propertyType'
          },
          exist(value) {
            if (value.bindMethod === 1) {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '标签',
          prop: 'label',
          exist(value) {
            if (value.bindMethod === 2) {
              return true
            } else {
              return false
            }
          }
        },
        //  app与pc不同之处
        {
          type: 'color',
          prop: 'checkedColor',
          label: '选中颜色',
          config: {
            position: 'right'
          },
          exist() {
            if (this.$attrs.device === 'APP') {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'select',
          label: '样式',
          prop: 'radioType',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [{ label: '单选框组', value: 'radioNormal' }, { label: '单选button', value: 'radioButton' }]
          },
          rules: [{ required: true, message: '请选择单选样式', trigger: 'change' }]
        },
        // {
        //   type: configTable,
        //   labelWidth: '0px',
        //   prop: 'options'
        // },
        {
          type: 'select',
          label: '连接类型',
          prop: 'connectType',
          config: {
            optionsValueKey: 'value',
            optionsLabelKey: 'label',
            returnObject: false,
            options: [
              { label: '数据字典', value: 'dictionary' },
              { label: '数据接口', value: 'interface' }
            ]
          },
          rules: [{ required: true, message: '请选择连接类型', trigger: 'change' }]
        },
        {
          type: 'select',
          label: '数据接口',
          prop: 'dataInterfaceId',
          config: {
            optionsValueKey: 'name',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getApiList()
            }
          },
          rules: [{ required: true, message: '请选择数据接口', trigger: 'change' }],
          exist(value) {
            if (value.connectType === 'interface') {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'button',
          label: '',
          labelWidth: '0',
          config: {
            label: '查询接口',
            position: 'right'
          },
          prop: 'searchClick',
          exist(value) {
            if (value.connectType === 'interface') {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '',
          labelWidth: '0',
          prop: 'optionsLabelKey',
          config: {
            label: '显示值字段'
          },
          rules: [{ required: true, message: '请输入显示值字段', trigger: 'blur' }],
          exist(value) {
            if (value.connectType === 'interface') {
              return true
            } else {
              return false
            }
          }
        },
        {
          type: 'input',
          label: '',
          labelWidth: '0',
          config: {
            label: '绑定值字段'
          },
          prop: 'optionsValueKey',
          rules: [{ required: true, message: '请输入绑定值字段', trigger: 'blur' }],
          exist(value) {
            if (value.connectType === 'interface') {
              return true
            } else {
              return false
            }
          }
        },
        // {
        //   type: 'checkbox',
        //   label: '关联查询',
        //   prop: 'linkSearch',
        //   exist(value) {
        //     if (value.connectType === 'interface') {
        //       return true
        //     } else {
        //       return false
        //     }
        //   }
        // },
        // {
        //   type: 'input',
        //   label: '关联查询表达式',
        //   prop: 'linkSearchEx',
        //   rules: [{ required: true, message: '请输入关联查询表达式', trigger: 'blur' }],
        //   exist(value) {
        //     if (value.linkSearch && value.connectType === 'interface') {
        //       return true
        //     } else {
        //       return false
        //     }
        //   }
        // },
        // {
        //   type: 'input',
        //   label: '关联查询参数名',
        //   prop: 'linkSearchQueryKey',
        //   rules: [{ required: true, message: '请输入关联查询参数名', trigger: 'blur' }],
        //   exist(value) {
        //     if (value.linkSearch && value.connectType === 'interface') {
        //       return true
        //     } else {
        //       return false
        //     }
        //   }
        // },
        {
          type: 'select',
          label: '数据字典',
          prop: 'dataDictionaryId',
          config: {
            optionsValueKey: 'id',
            optionsLabelKey: 'name',
            returnObject: false,
            options() {
              return getDictionaryTypeList()
            }
          },
          exist(value) {
            if (value.connectType === 'dictionary') {
              return true
            } else {
              return false
            }
          }
          // rules: [{ required: true, message: '请选择数据字典', trigger: 'change' }]
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否必填',
            position: 'right'
          },
          label: '是否必填',
          prop: 'required'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否可见',
            position: 'right'
          },
          label: '是否可见',
          prop: 'isShowExp'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            lineNumbers: 'on',
            title: '是否存在',
            position: 'right'
          },
          label: '是否存在',
          prop: 'isExistExp'
        },
        {
          type: 'commonConfigEditor',
          config: {
            marginLeft: -80,
            height: '300px',
            lineNumbers: 'on',
            title: '是否只读',
            position: 'right'
          },
          label: '是否只读',
          prop: 'isReadonlyExp'
        }
      ]
    }, /* {
      title: '组件事件',
      columnsCount: 2,
      items: [
        {
          type: 'monacoEditor',
          label: '',
          labelWidth: '0',
          config: {
            label: 'change',
            height: '300px',
            lineNumbers: 'on',
            position: 'right',
            haveIcon: true
          },
          prop: 'changeCb'
        }
      ]
    } */
  ]
}
